class Predio < ActiveRecord::Base
	validates :sigla, :presence => true, :uniqueness => true, :uniqueness => {:case_sensitive => false}
	validates :nome, :presence => true, :uniqueness => true, :uniqueness => {:case_sensitive => false}
	validates :campus, :presence => true, :uniqueness => {:case_sensitive => false}
	validates :rua, :presence => true, :uniqueness => {:case_sensitive => false}
	validates :numero, :presence => true, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }
	validates :bairro, :presence => true, :uniqueness => {:case_sensitive => false}
	validates :andar, :presence => true, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }


	has_many :salasdeaula, :through => :Predio
	has_many :atividade, :through => :Salasdeaula
	has_many :instituto, :through => :predio_instituto

	def self.searchSiglaNome(query)
	    if query
	      find(:all, :conditions => ['sigla LIKE :query OR nome LIKE :query', {:query => "%#{query}%"}], :order => 'sigla ASC')
	    else
	      all(:order => 'nome ASC')
	    end
 	end
end
